package com.app.toknow.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.toknow.R;

import com.app.toknow.Entity.MainMenuItemInfo;


import java.util.LinkedList;

/**
 * Created by kangw on 2015/10/4.
 */
public class MainMenuListAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private LinkedList<MainMenuItemInfo> list;

    public MainMenuListAdapter(Context context, LinkedList<MainMenuItemInfo> list) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.main_menu_item, null);

            holder = new ViewHolder();
            holder.itemHeadImage = (ImageView) convertView.findViewById(R.id.itemMenuIcon);
            holder.itemContent = (TextView) convertView.findViewById(R.id.itemMenuText);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final MainMenuItemInfo itemInfo = list.get(position);
        holder.itemHeadImage.setImageDrawable(itemInfo.getIconRes());
        holder.itemContent.setText(itemInfo.getContent());
        return convertView;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public class ViewHolder {
        public ImageView itemHeadImage;
        public TextView itemContent;
    }
}
